package cn.schoolwow.ams.module.block.listBlock.clazzBlock.api.flow;

import cn.schoolwow.ams.domain.block.list.clazz.crud.ClazzListBlockListListener;
import cn.schoolwow.ams.domain.block.list.common.ListBlockPagingResponse;
import cn.schoolwow.ams.module.block.listBlock.clazzBlock.initial.domain.ClazzListBlockContext;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import com.alibaba.fastjson.JSONObject;

public class ExecuteClazzListBlockPagingListenerFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        String projectName = (String) flowContext.checkData("projectName");
        String clazzName = (String) flowContext.checkData("clazzName");
        ClazzListBlockContext clazzListBlockContext = flowContext.checkInstanceData(ClazzListBlockContext.class);
        JSONObject conditionMap = (JSONObject) flowContext.checkData("conditionMap");

        ClazzListBlockListListener clazzListBlockListListener = clazzListBlockContext.clazzListBlockAPIListener.listListener;
        if(null== clazzListBlockListListener){
            throw new IllegalArgumentException("当前列表未配置分页查询逻辑!项目名:"+projectName+",clazz名称:"+clazzName);
        }
        ListBlockPagingResponse listBlockPagingResponse = clazzListBlockListListener.list(conditionMap);
        flowContext.putTemporaryInstanceData(listBlockPagingResponse);
    }

    @Override
    public String name() {
        return "执行ClazzListBlock类型的列表分页逻辑";
    }

}
